﻿using Rj_GsInsurance.Client.ControlsLookup;
using Rj_GsInsurance.Client.ViewModels;
using Rj_GsInsurance.Server.DataBaseContext.Entities;
using Rj_GsInsurance.Server.DataBaseContext;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Wpf.Ui.Controls;
using Microsoft.EntityFrameworkCore;

namespace Rj_GsInsurance.Client.Pages
{
    /// <summary>
    /// ApprovalManagePage.xaml 的交互逻辑
    /// </summary>
    [GalleryPage("审批信息上报", SymbolRegular.AlbumAdd24)]
    public partial class ApprovalManagePage : INavigableView<ApprovalManageViewModel>
    {
        public ApprovalManageViewModel ViewModel { get; }
        public ApprovalManagePage(ApprovalManageViewModel viewModel)
        {
            ViewModel = viewModel;
            this.DataContext = this;
            InitializeComponent();
        }

        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            await Task.Run(() =>
            {
                ViewModel.DiagViewModel = new ObservableCollection<DiagViewModel>(ViewModel.HisDbContext.InsurWorkInjuryDiseaseCatalogues.Take(100).ToList().Select(s => new DiagViewModel() { Bzbm = s.Jbbm, Bzmc = s.Jbmc }));
                //DiagnosisViewModel = new ObservableCollection<DiagViewModel>(HisDbContext.SystemTbDiagnoses.ToList().Select(s=>new DiagViewModel() { Bzbm=s.DiagnosisCode,Bzmc=s.DiagnosisName}));
                ViewModel.AuxiliaryEquipments = new ObservableCollection<InsurWorkInjuryAuxiliaryEquipment>(ViewModel.HisDbContext.InsurWorkInjuryAuxiliaryEquipments.ToList());
                ViewModel.ApprovalFzqjViewModel = new ObservableCollection<ApprovalManageFzqjViewModel>();
            });
        }

        private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
            if (string.IsNullOrEmpty((e.PropertyDescriptor as System.ComponentModel.PropertyDescriptor).Description))
            {
                e.Column.Visibility = Visibility.Collapsed;
            }
            else
            {
                e.Column.Header = (e.PropertyDescriptor as System.ComponentModel.PropertyDescriptor).Description;
            }
        }
    }
}
